//
//  CCMHomeVC.swift
//  CCMoney_swift
//
//  Created by JKHuang on 2018/11/22.
//  Copyright © 2018 JKHuang. All rights reserved.
//

import UIKit

#if !RX_NO_MODULE
import RxSwift
import RxCocoa
#endif

fileprivate let kCCMHomeViewCell = "CCMHomeViewCell"
fileprivate let kUITableViewCell = "UITableViewCell"
fileprivate let kCCMMineOrderItemViewCell = "CCMMineOrderItemViewCell"
fileprivate let kCCMMineViewCell = "CCMMineViewCell"

class CCMHomeVC: CCMBaseViewController {
    

    fileprivate lazy var TableViw: UITableView = {
        
        let tableView : UITableView = UITableView(frame: CGRect(x: 0, y: kNavigationHeight, width: ScreenWidth, height: ScreenHeight-kNavigationHeight), style: .plain)
        tableView.backgroundColor = MainColor
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(CCMHomeViewCell.self, forCellReuseIdentifier: kCCMHomeViewCell)
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: kUITableViewCell)
        tableView.register(CCMMineViewCell.self, forCellReuseIdentifier: kCCMMineViewCell)
        tableView.register(CCMMineOrderItemViewCell.self, forCellReuseIdentifier: kCCMMineOrderItemViewCell)
        tableView.backgroundColor = MainColor
        tableView.separatorStyle = .none
        return tableView
    }()
    
    let messageButton : UIButton = {
        let button = UIButton()
        button.setTitle("消息", for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.addTarget(self, action: #selector(clickRightBut), for: .touchUpInside)
        return button
    }()
    
    let passTimeBut : UIButton = {
        let button = UIButton()
        button.setTitle("超时处罚", for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.addTarget(self, action: #selector(clickRightBut), for: .touchUpInside)
        return button
    }()
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        self.navigationItem.title = "工作台"
        self.hiddenCustomBack = true
        setUI()
        // Do any additional setup after loading the view.
    }

}

extension CCMHomeVC{
    
    fileprivate func setUI() {
        
        let rightItem = UIBarButtonItem(customView: messageButton)
        self.navigationItem.leftBarButtonItem = rightItem
        
        view.addSubview(TableViw)
        TableViw.snp.makeConstraints { (make) in
            make.edges.equalTo(view)
        }
    }
    
    @objc fileprivate func clickRightBut(){
        
    }
}

extension CCMHomeVC:UITableViewDataSource,UITableViewDelegate{
    
    func numberOfSections(in tableView: UITableView) -> Int {
        
        return 4
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        if section == 3 {
            return 5
        }
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        switch indexPath.section {
        case 0:
           
            let cell = tableView.dequeueReusableCell(withIdentifier: kCCMMineOrderItemViewCell, for: indexPath) as!CCMMineOrderItemViewCell
            cell.selectionStyle = .none
            return cell
            
        case 1:
            
            let cell = tableView.dequeueReusableCell(withIdentifier: kCCMMineViewCell, for: indexPath) as!CCMMineViewCell
            cell.backgroundColor = UIColor.hex(0x2D3554)
            cell.titleLable.text = "待处理订单"
            cell.contentLable.text = "全部订单"
            cell.lineView.isHidden = true
            cell.contentLable.isHidden = false
            cell.selectionStyle = .none
            return cell
            
        case 2:
            
            let cell = tableView.dequeueReusableCell(withIdentifier: kUITableViewCell)
            cell!.backgroundColor = UIColor.hex(0x2D3554)
            cell!.selectionStyle = .none
            cell?.contentView.addSubview(passTimeBut)
            passTimeBut.snp.makeConstraints({ (make) in
                make.leading.equalTo(15)
                make.centerY.equalTo((cell?.contentView)!)
            })
            return cell!
            
        default:
            let cell = tableView.dequeueReusableCell(withIdentifier: kCCMHomeViewCell, for: indexPath) as!CCMHomeViewCell
            cell.backgroundColor = MainColor
            cell.selectionStyle = .none
            return cell
        }
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        switch indexPath.section {
        case 0:
            return 80
        case 1:
            return 44
        case 2:
            return 44
        default:
            return 150
        }
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        
        return 0.5
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        
        return UIView()
    }
    
}

